﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Exercise2.Models;

namespace Exercise2.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to the climb archive on ASP.NET MVC!";

            var _repository = new ClimbRepository();
            SendClimbListToView(_repository);

            return View();
        }

        public ActionResult Climb(string name)
        {
            var _repository = new ClimbRepository();

            Climb climb = _repository.GetClimb(name);

            SendClimbListToView(_repository);
            return View(climb);
        }

        private void SendClimbListToView(ClimbRepository _repository)
        {
            var climbs = _repository.GetTopClimbs();
            ViewData["Climbs"] = climbs;
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
